package cn.edut.dao;

/**
 * @Author ruanxin
 */

import cn.edut.domain.User;
import cn.edut.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

/*
 *
 * 操作数据库表
 * */
public class UserDao {

    //声明JDBCTemplate对象共用
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getdatasoure());

    /**
     * 登录方法
     *
     * @param loginUser 只有用户名和密码
     * @return User查询用户所有数据，查询不到，返回null
     */
    public User login(User loginUser) {
        try {
            String sql = "select * from user where username = ? and userpassword = ?";
            User user = template.queryForObject(sql,
                    new BeanPropertyRowMapper<User>(User.class),
                    loginUser.getUsername(), loginUser.getUserpassword());
            return user;
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }

    }


}

